// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT

import {
    AboutSlint, Button, GridBox, HorizontalBox, LineEdit, Slider,
    StandardButton, StandardListView, TabWidget, VerticalBox
} from "std-widgets.slint";


export component Demo inherits Window {
    in property <string> firmware-vendor;
    in property <string> firmware-version;
    in property <string> uefi-version;
    in property <bool> secure-boot;

    default-font-size: 30px;

    TabWidget {
        width: root.width;
        height: root.height;
              Tab {
                   title: "标准部件";
                   VerticalBox {
                       enabler := Button {
                           checked: true;
                           checkable: true;
                           text: "使能 Widgets ";
                       }

                       LineEdit {
                           enabled: enabler.checked;
                           placeholder-text: "点击编辑";
                       }

                       Slider {
                           enabled: enabler.checked;
                       }

                       StandardListView {
                           vertical-stretch: 1;
                           enabled: enabler.checked;
                           model: [
                               { text: "中文支持1"}, { text: "中文支持2" }, { text: "中文支持3" },
                               { text: "中文支持4" }, { text: "中文支持5"}, { text: "中文支持6"},
                               { text: "中文支持7" }, { text: "中文支持8" },  { text: "中文支持9"},
                           ];
                       }

                       HorizontalBox {
                           alignment: center;

                           StandardButton { enabled: enabler.checked; kind: ok; }
                           StandardButton { enabled: enabler.checked; kind: reset; }
                           StandardButton { enabled: enabler.checked; kind: abort; }
                       }
                   }
               }


        Tab {
            title: "系统信息";
            GridBox {
                Row { Rectangle {} }

                Row {
                    Text {
                        colspan: 2;
                        text: "中文字体";
                        horizontal-alignment: center;
                        font-size: 44px;
                        font-weight: 800;
                    }
                }

                Row {
                    HorizontalLayout {
                        colspan: 2;
                        alignment: center;
                        AboutSlint {
                            width: 256px;
                        }
                    }
                }

                Row {
                    Text { text: "Firmware vendor:"; horizontal-alignment: right;  }
                    Text { text: firmware-vendor; }
                }

                Row {
                    Text { text: "Firmware version:"; horizontal-alignment: right; }
                    Text { text: firmware-version; }
                }

                Row {
                    Text { text: "UEFI version:"; horizontal-alignment: right; }
                    Text { text: uefi-version; }
                }

                Row {
                    Text { text: "Secure boot:"; horizontal-alignment: right; }
                    Text { text: secure-boot ? "enabled" : "disabled"; }
                }

                Row {
                    Text { text: "Resolution:"; horizontal-alignment: right; }
                    Text { text: "\{floor(root.width / 1px)}x\{floor(root.height / 1px)}"; }
                }

                Row { Rectangle {} }
            }
        }


        Tab {
            title: "V-Sync 测试";

            Rectangle {
                for color[index] in [
                        #fff, #f00, #0f0,
                        #00f, #0ff, #ff0,
                        #f0f]: Rectangle {
                    y: 0;
                    height: parent.height;
                    x: (parent.width - self.width) * 0.5 *
                       (1 + 1.1 * sin(animation-tick() * (index + 1) / 17ms * 1deg));
                    width: 25px + 100px * abs(sin(animation-tick() / 25ms * 1deg));
                    background: color;
                }
            }
        }





    }
}
